// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		riderinfo: uni.getStorageSync('riderinfo') ? JSON.parse(uni.getStorageSync('riderinfo')) : '',
		rider_token: uni.getStorageSync('rider_token') ? uni.getStorageSync('rider_token') : '',
		rider_id: uni.getStorageSync('rider_id') ? uni.getStorageSync('rider_id') : '',
		lang: uni.getStorageSync('lang') ? uni.getStorageSync('lang') : 'cn',
		location: '',
		address: '',
		ugaddress: '',
		tops:uni.getStorageSync('tops') ? JSON.parse(uni.getStorageSync('tops')) : '',
		shop: {
			totalprice: 0,
			totalnumber: 0,
			totalshop: []
		},
		keyboard: false
	},
	getters: {
		getuserinfo(state) {
			return state.riderinfo
		},
		gettoken(state) {
			return state.rider_token
		},
		getlocation(state) {
			return state.location
		},
		getaddress(state) {
			return state.address
		},
		getugaddress(state) {
			return state.ugaddress
		},
		getrider_id(state) {
			return state.rider_id
		}
	},
	mutations: {
		//键盘监听--H5键盘有问题
		setKeyboard(state, keyboard) {
			state.keyboard = keyboard;
		},
		//用户信息
		setUserinfo(state, e) {
			uni.setStorageSync('riderinfo', JSON.stringify(e))
			state.riderinfo = e;
		},
		//token
		setUsertoken(state, e) {
			uni.setStorageSync('rider_token', e)
			state.rider_token = e;
		},
		//语言
		setLang(state, lang) {
			uni.setStorageSync('lang', lang)
			state.lang = lang;
			// postlang({
			// 	language: lang == 'ug' ? 'ug' : 'zh_CN'
			// }).then((res) => {
			// 	if (res.code == 200) {
			// 	}
			// })
		},
		//地址
		setLocation(state, location) {
			state.location = location;
		},
		//地址
		setAddress(state, address) {
			state.address = address;
		},
		//维吾尔语地址
		setugAddress(state, ugaddress) {
			state.ugaddress = ugaddress;
		},
		//rider_id
		setRiderid(state, id) {
			uni.setStorageSync('rider_id', id)
			state.rider_id = id;
		},
		//配送地址
		setTops(state, tops){
			uni.setStorageSync('tops', JSON.stringify(tops))
			state.tops = tops;
		}
	}
})
export default store